package com.mark.beetl.controller;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.mark.beetl.entity.User;
import com.mark.beetl.service.UserService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;
import org.beetl.sql.core.annotatoin.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 首页controller
 *
 * @author maliqiang
 * @version 1.0
 * @create 2017-03-27
 */
@Controller
@Api("首页")
public class IndexController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/zui", method = RequestMethod.GET)
    public String zui() {
        return "index.jsp";
    }

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public ModelAndView index() {
        User user = userService.queryById(1);
        ModelAndView view = new ModelAndView("index");
        view.addObject("user",user);
        return view;
    }

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public ModelAndView showAll() {
        List<User> users = userService.queryAll();
        ModelAndView view = new ModelAndView("users");
        view.addObject("users",users);
        return view;
    }

    @ResponseBody
    @RequestMapping(value = "/test",method = {RequestMethod.POST,RequestMethod.GET})
    @ApiOperation(value = "测试方法")
//    @ApiResponses(value={@ApiResponse(code=200,message="商品信息")})
    public String testJson(){
        return "{\"flag\":\"success\"}";
    }

    @ApiIgnore//生成接口文档时忽略
    @RequestMapping("/info")
    public ModelAndView swaggerInfo() {
        String url="redirect:swagger/index.html";
        return new ModelAndView(url);
    }
}
